package com.example.myapplicationtest12

import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.LinearLayout
import android.widget.ScrollView

import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity

import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        //第一部分
        val container=findViewById<LinearLayout>(R.id.container)
        var num=0
        val button=findViewById<Button>(R.id.button)
        val scrollView=findViewById<ScrollView>(R.id.scrollView)


        button.setOnClickListener {
            val textView= TextView(this)//每次点击之后textView要重新建立一个
            num++
            textView.text=getString(R.string.textView,num)//针对kotlin的转换字符串要这么写
            textView.textSize=20f
            container.addView(textView)//在scrollView中添加入该文本标签
            scrollView.fullScroll(View.FOCUS_DOWN)//实现scrollView添加之后自动滑动，无须手动
        }

        //第二部分代码
        val feature= ProgremAdviser()
        val button1=findViewById<Button>(R.id.button1)
        val textView2=findViewById<TextView>(R.id.textView2)
        val spinner=findViewById<Spinner>(R.id.spinner)
        button1.setOnClickListener {
            //val selectedFeature= spinner.selectedItem.toString()
            textView2.text=feature.getLanguage(spinner.selectedItem.toString())
        }
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
    }
}